package com.caregiver.watch.business.care.model.vo;

import com.caregiver.watch.business.data.enums.SleepTypeEnum;
import com.caregiver.watch.business.user.enums.WeekDay;
import com.caregiver.watch.common.utils.time.DateUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 睡眠详情
 * @program: caregiver-watch
 * @author: 疆戟
 * @create: 2025-10-01 16:26
 */
@Data
@Schema(description = "睡眠详情")
public class SleepDetailVo {

    // 日期
    @Schema(description = "日期")
    private LocalDate date;
    // 星期
    @Schema(description = "星期")
    private WeekDay week;

    @Schema(description = "睡眠开始时间")
    private LocalDateTime sleepStartTime;

    @Schema(description = "睡眠结束时间")
    private LocalDateTime sleepEndTime;

    @Schema(description = "睡眠总时长")
    private Integer sleepDuration;

    @Schema(description = "深度睡眠时长,单位分钟")
    private Integer deepSleepDuration;

    @Schema(description = "深度睡眠时长占比")
    private BigDecimal deepSleepDurationPercent;

    @Schema(description = "浅睡时长,单位分钟")
    private Integer lightSleepDuration;

    @Schema(description = "浅睡时长占比")
    private BigDecimal lightSleepDurationPercent;
    // 快速眼动时间
    @Schema(description = "快速眼动时长,单位分钟")
    private Integer rapidEyeMovementDuration;

    @Schema(description = "快速眼动时长占比")
    private BigDecimal rapidEyeMovementDurationPercent;
    // 清醒时间
    @Schema(description = "清醒时长,单位分钟")
    private Integer wakeUpDuration;

    @Schema(description = "清醒时长占比")
    private BigDecimal wakeUpDurationPercent;

    @Schema(description = "睡眠总得分")
    private Integer sleepScore;

    @Schema(description = "睡眠阶段")
    private List<SleepSectionVo> sleepSection;


    @Data
    @Schema(description = "睡眠阶段")
    public static class SleepSectionVo {

        /**
         * 开始时间
         */
        @Schema(description = "开始时间")
        private Integer start;

        /**
         * 结束时间
         */
        @Schema(description = "结束时间")
        private Integer end;

        /**
         * 类型
         */
        @Schema(description = "类型 DEEP_SLEEP 3 深睡 LIGHT_SLEEP 4 浅睡 WAKE_UP 6 清醒 FAST_EYE_MOVEMENT 7 快速眼动")
        private SleepTypeEnum type;

        public static SleepSectionVo build(LocalDateTime start, LocalDateTime end, Integer type) {
            SleepSectionVo sleepSectionVo = new SleepSectionVo();
            sleepSectionVo.start = DateUtils.getMinute(start);
            sleepSectionVo.end = DateUtils.getMinute(end);
            sleepSectionVo.type = SleepTypeEnum.pares(type);
            return sleepSectionVo;
        }
    }
}
